<html>
<head><meta charset="utf-8"><title>function args vs. target · t-compiler/wg-nll · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/index.html">t-compiler/wg-nll</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/function.20args.20vs.2E.20target.html">function args vs. target</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="193217765"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/function%20args%20vs.%20target/near/193217765" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Russell Cohen <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/function.20args.20vs.2E.20target.html#193217765">(Apr 07 2020 at 16:58)</a>:</h4>
<p>Someone posted this example on twitter: <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=a4232dffd9300e6febeabf2208ea589d" title="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=a4232dffd9300e6febeabf2208ea589d">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=a4232dffd9300e6febeabf2208ea589d</a> which I thought was interesting -- The argument borrow _could_ end before we borrow self, but obviously it doesn't. I was curious what would be needed to fix this. (Obviously in this example you could just do <code>self.a</code>, but the user says IRL they needed a mut ref)</p>



<a name="193217945"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/function%20args%20vs.%20target/near/193217945" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Russell Cohen <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/function.20args.20vs.2E.20target.html#193217945">(Apr 07 2020 at 17:00)</a>:</h4>
<p>for clarity:</p>
<div class="codehilite"><pre><span></span>struct Foo {
    a: usize,
}

impl Foo {
    fn bad(&amp;mut self) {
        let ref mut b = self.a;
        self.doit(*b);
    }
   fn doit(&amp;mut self, _b: usize) {}
}
</pre></div>



<a name="193449335"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/function%20args%20vs.%20target/near/193449335" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/function.20args.20vs.2E.20target.html#193449335">(Apr 09 2020 at 13:25)</a>:</h4>
<p>Is this similar to two-phase borrows?</p>



<a name="193449412"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/function%20args%20vs.%20target/near/193449412" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/function.20args.20vs.2E.20target.html#193449412">(Apr 09 2020 at 13:26)</a>:</h4>
<p>I think it may <em>be</em> two phase borrows</p>



<a name="193449435"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/function%20args%20vs.%20target/near/193449435" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/function.20args.20vs.2E.20target.html#193449435">(Apr 09 2020 at 13:26)</a>:</h4>
<p>(or "generalized two-phase borrows", rather)</p>



<a name="193468586"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/function%20args%20vs.%20target/near/193468586" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Russell Cohen <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/function.20args.20vs.2E.20target.html#193468586">(Apr 09 2020 at 15:46)</a>:</h4>
<p>oh, maybe. But because it's explicitly ref mut it isn't?</p>



<a name="193487467"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/function%20args%20vs.%20target/near/193487467" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/function.20args.20vs.2E.20target.html#193487467">(Apr 09 2020 at 18:05)</a>:</h4>
<p>I don't know yet</p>



<a name="193487494"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/function%20args%20vs.%20target/near/193487494" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/function.20args.20vs.2E.20target.html#193487494">(Apr 09 2020 at 18:05)</a>:</h4>
<p>It just struck me as quite similar</p>



<a name="194539833"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/function%20args%20vs.%20target/near/194539833" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/function.20args.20vs.2E.20target.html#194539833">(Apr 18 2020 at 11:32)</a>:</h4>
<p><span class="user-mention" data-user-id="279742">@Russell Cohen</span> I think <span class="user-mention" data-user-id="116083">@pnkfelix</span> is correct that this is related to two-phase borrows, but there are two complications:</p>
<ul>
<li>first, we decided not to support mixing two <code>&amp;mut</code>  references</li>
<li>second, this is a case of a "pre-existing borrow', which we also decided to forbid, as it is incompatible with two-phase borrows (See e.g. <a href="https://github.com/rust-lang/rust/issues/59159" title="https://github.com/rust-lang/rust/issues/59159">#59159</a>, <a href="https://github.com/rust-lang/rust/issues/56254" title="https://github.com/rust-lang/rust/issues/56254">#56254</a>)</li>
</ul>



<a name="195098647"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/function%20args%20vs.%20target/near/195098647" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Russell Cohen <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/function.20args.20vs.2E.20target.html#195098647">(Apr 23 2020 at 18:07)</a>:</h4>
<p>Got it. So theoretically it could be handled in exactly this form, but the generalized form causes issues.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>